#pragma once
#include "udp/udp_server.hpp"
typedef void (*CanCallBack)(uint32_t id, uint8_t dlc, uint8_t *data);
typedef void (*CAN_CALLBACK)(void *, uint32_t id, uint8_t length, uint8_t *data);

struct CAN_DATA_TEMP
{
    uint32_t id;
    uint8_t l;
    uint8_t *data;
};

class UDP_CAN : private ADEALL_UDP_SERVER
{
private:
    /* data */
public:
    UDP_CAN(/* args */);
    ~UDP_CAN();

    int Init_CAN(int port);
    void Send(uint32_t id, uint8_t *data, uint8_t dlc, const char *ip = "192.168.4.101", int port = 8881);
    CanCallBack canCallBackprt = nullptr;

protected:
    virtual void canCallBackfun(uint32_t id, uint8_t dlc, uint8_t *data);
    // udp 回调函数
    void CallBackFuntion(std::string ip, int port, std::vector<uint8_t>, void *);

private:
    CAN_DATA_TEMP data_temp;
    CAN_CALLBACK callback = nullptr;
    void *context;
    static void *Th_CAN_msg_cb_once(void *);
};
